﻿@using Kugar.Core.BaseStruct
@using Kugar.Core.Configuration
@using Kugar.Core.ExtMethod
@using Kugar.UI.Web.AdminLTE
@using Kugar.UI.Web.AdminLTE.Enums
@using Kugar.UI.Web.AdminLTE.Helpers
@using Kugar.UI.Web.AdminLTE.Models
@using Kugar.UI.Web.AdminLTE.PageControls
@using Kugar.UI.Web.AdminLTE.PageControls.Helpers.ButtonExtMethod
@using Kugar.UI.Web.AdminLTE.PageControls.PageCommon
@using Newtonsoft.Json.Linq
@model Kugar.UI.Web.AdminLTE.Models.Model_AdminList

@inject AdminLTEUI WebUI

@{
    if (Model.IsIFrame)
    {
        Layout = AdminLTEUI.LayoutPath.LayoutWithIFramePath_Content;
    }
    else
    {
        var configLayout = CustomConfigManager.Default["AdminLTE:AdminManagerLayout"];

        if (!string.IsNullOrWhiteSpace(configLayout))
        {
            Layout = configLayout;
        }
        else
        {
            Layout = AdminLTEUI.LayoutPath.DefaultLayoutPath;
        }

    }

    WebUI.Title = "管理员列表";
    WebUI.CurrentMenuKey = CustomConfigManager.Default["AdminLTE:AdminListCurrentMenuKey"];
}

@using (var dl=WebUI.Control.DataList<Model_AdminInfo>().Render())
{
    @(dl.FilterBlock.AddTextBox(x=>x.BoxItemLabel("关键字").Name("Keyword").PlaceHolder("管理员账号").SelectedOnClick(true).Value(Model.Keyword))
          .HideQueryButton()
          .AddHiddenValue("IsIFrame", Model.IsIFrame.ToStringEx())
          .AddSelector(x=>x.BoxItemLabel("状态").Name("State").Options(new []
                                                              {
                                                                  new SelectorItem("全部","-1"),
                                                                  new SelectorItem("正常","0"),
                                                                  new SelectorItem("禁用","99"),
                                                              }))
          .AddButton(x=>x.Type(ButtonTypeEnum.submit).Color(ColorPaletteEnum.primary).Text("查询"))
          .Render())

    using (var db = dl.DataBlock
        .AddRightSideButton((btn) => btn.Text("新建管理员").ShowModal("AdminDetail").Color(ColorPaletteEnum.success))
        .Render()
    )
    {
        using (var table = db.Table.Data(Model.List).NoWrap().LeftFixedColumn(1).RightFixedColumn(1).Render())
        {
            @table.Columns.AddIndex()

            @table.Columns.AddLabel().ColumnTitle("账号").Value(x=>x.UserName)

            @table.Columns.AddLabel().ColumnTitle("最后登录时间").Value(x=>x.LastLoginDt.ToStringEx("yyyy-MM-dd HH:mm"))

            @table.Columns.AddLabel().ColumnTitle("状态").Value(x=>x.State==0?"正常":"停用")

            @(table.Columns.AddButtonList().ButtonType(ColumnDropdownButtonType.ButtonList)
                  .AddButton((data,btn)=>btn.Text("详情").ShowModal("AdminDetail?userid=" + data.UserID).Color(ColorPaletteEnum.primary))
                  
                  .AddButton((data,btn)=>btn.Text("停用").ExecuteCmd("AdminMethod","stop",new JObject()
                  {
                      ["UserID"]=data.UserID
                  }, "", "", true).Color(ColorPaletteEnum.warning).Hide(data.State==99))
                  
                  .AddButton((data,btn)=>btn.Text("启用").ExecuteCmd("AdminMethod","start",new JObject()
                  {
                      ["UserID"]=data.UserID
                  }, "", "", true).Color(ColorPaletteEnum.warning).Hide(data.State==0))
                  
                  .AddButton((data,btn)=>btn.Text("重置密码").ExecuteCmd("AdminMethod","resetpassword",new JObject()
                  {
                      ["UserID"]=data.UserID
                  }, "", "确定重置密码？", true).Color(ColorPaletteEnum.danger).Hide(data.State==99))
                  
                  .AddButton((data,btn)=>btn.Text("删除").ExecuteCmd("AdminMethod","delete",new JObject()
                  {
                      ["UserID"]=data.UserID
                  },"","确定删除？",true).Color(ColorPaletteEnum.danger)))
        }

    }
}
